package cn.itsource.basic.service.impl;

import cn.itsource.basic.mapper.BaseMapper;
import cn.itsource.basic.query.BaseQuery;
import cn.itsource.basic.service.IBaseService;
import cn.itsource.basic.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;


    @Override
    @Transactional
    /**
     * 添加
     */
    public void add(T t) {
       mapper.add(t);
    }

    @Override
    @Transactional
    /**
     * 修改
     */
    public void update(T t) {
     mapper.update(t);
    }

    @Override
    @Transactional
    /**
     * 删除
     */
    public void del(Long id) {
        mapper.del(id);

    }

    @Override
    /**
     * 根据id查询
     */
    public T querybyid(Long id) {
        return mapper.querybyid(id);
    }

    @Override
    /**
     * 查询所有
     */
    public List<T> qaueryall() {
        return mapper.qaueryall();
    }


    @Override
    /**
     * 高级查询加分页
     */
    public PageBean<T> queryhigt(BaseQuery query) {
        Integer count = mapper.count(query);
            if(count==0 || count<=0){
            return new PageBean<>();
        }else {
            List<T> list = mapper.queryhigt(query);
            return new PageBean<T>(count,list);
        }
    }
}
